// pages/bank-card/bank-card.ts
interface BankCard {
  id: string;
  bankName: string;
  lastFour: string;
  accountType: string;
  expiry?: string;
  isDefault: boolean;
}

Page({
  data: {
    statusBarHeight: 0,
    bankCards: [
      {
        id: '1',
        bankName: '工商银行储蓄卡',
        lastFour: '8888',
        accountType: '默认收款户',
        isDefault: true
      },
      {
        id: '2',
        bankName: '招商银行信用卡',
        lastFour: '6666',
        accountType: '有效期',
        expiry: '05/28',
        isDefault: false
      }
    ] as BankCard[]
  },

  onLoad() {
    const systemInfo = wx.getSystemInfoSync();
    this.setData({
      statusBarHeight: systemInfo.statusBarHeight || 0
    });
  },

  goBack() {
    wx.navigateBack();
  },

  addBankCard() {
    wx.showToast({
      title: '添加银行卡功能开发中',
      icon: 'none'
    });
  },

  editCard(e: any) {
    const id = e.currentTarget.dataset.id;
    wx.showToast({
      title: '编辑银行卡: ' + id,
      icon: 'none'
    });
  },

  showCardOptions(e: any) {
    const id = e.currentTarget.dataset.id;
    wx.showActionSheet({
      itemList: ['设为默认', '解绑银行卡'],
      success: (res) => {
        if (res.tapIndex === 0) {
          wx.showToast({ title: '已设为默认', icon: 'success' });
        } else if (res.tapIndex === 1) {
          wx.showModal({
            title: '解绑银行卡',
            content: '确定要解绑该银行卡吗？',
            success: (modalRes) => {
              if (modalRes.confirm) {
                wx.showToast({ title: '已解绑', icon: 'success' });
              }
            }
          });
        }
      }
    });
  }
});
